<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>爬虫管理</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <link rel="stylesheet" href="../../../lib/layui-v2.5.5/css/layui.css" media="all">
        <link rel="stylesheet" href="../../../css/public.css" media="all">
    </head>
    <body>
        <div class="layuimini-container">
            <div class="layuimini-main">
                <fieldset class="layui-elem-field site-demo-button">
                    <legend>开启爬虫</legend>
                    <div style="margin: 10px 10px 10px 10px">
                        <button type="button" class="layui-btn layui-btn-normal layui-btn-radius  layui-icon" id="start">&nbsp;&nbsp;&nbsp;&nbsp;&#xe609;&nbsp;&nbsp;&nbsp;&nbsp;</button>
                    </div>
                </fieldset>
                <fieldset class="layui-elem-field site-demo-button">
                    <legend>查看爬虫状态</legend>
                    <div style="margin: 10px 10px 10px 10px">
                        <button type="button" class="layui-btn layui-btn-warm layui-btn-radius  layui-icon" id="show">&nbsp;&nbsp;&nbsp;&nbsp;&#xe60b;&nbsp;&nbsp;&nbsp;&nbsp;</button>
                        <tip id="show_tip">请先通过查看爬虫状态获取停用pid</tip>
                    </div>
                </fieldset>
                <fieldset class="layui-elem-field site-demo-button">
                    <legend>停止爬虫</legend>
                    <div style="margin: 10px 10px 10px 10px">
                        <button type="button" class="layui-btn layui-btn-danger layui-btn-radius layui-icon" id="kill">&nbsp;&nbsp;&nbsp;&nbsp;&#xe651;&nbsp;&nbsp;&nbsp;&nbsp;</button>
                            <div class="layui-input-inline">
                                <input type="text" name="pid"  id="pid" placeholder="请输入停用pid" autocomplete="off" class="layui-input" readonly="readonly" >
                            </div>

                        <tip>请先通过查看爬虫状态获取停用id</tip>
                    </div>
                </fieldset>

            </div>
        </div>
        <script src="../../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
        <script src="../../../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
        <script src="../../../lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
        <script src="../../../lib/jq-module/jquery.particleground.min.js" charset="utf-8"></script>
        <script src="../../../lib/common/jquery.cookie.min.js" charset="utf-8"></script>
        <script src="../../../lib/common/common.js" charset="utf-8"></script>
        <script type="text/javascript">
            layui.use(['layer'],function () {
                var layer = layui.layer;
                var pid;
                //启动
                $("#start").click(function () {
                    $.post(api+"crawler/start",function (rs) {
                        layer.msg(rs.msg);
                    })
                });
                //查看
                $("#show").click(function () {
                    $.post(api+"crawler/show",function (rs) {
                        if(rs.code != 200){
                            $("#show_tip").html(rs.msg).css("color","red");
                        }
                        if (rs.code == 200){
                            $("#show_tip").html(rs.msg).css("color","green");
                            var reg = new RegExp('\\d*/java')
                            pid =reg.exec(rs.data);
                            pid = pid.toString();
                            pid = pid.substring(0,pid.indexOf("/"));
                            $("#pid").val(pid);
                        }

                    })
                });
                //停用
                $("#kill").click(function () {
                    $.post(api+"crawler/kill",{pid:pid},function (rs) {
                        layer.msg(rs.msg);
                    });
                })
            })
        </script>
    </body>
</html>